package com.linjiu.xpermissionclent;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.widget.LinearLayout;
import android.widget.TextView;



/**
 * 项目名称：com.ebeitech.mPaaSDemo.launcher.dialog
 * 创建人:LuoFG
 * 创建时间:2022/10/28  17:32
 * 描述:
 * 作用:
 */
public class DialogPermissionTips implements View.OnClickListener {
    TextView tvTitle,tvContent;
    LinearLayout lineAll;
    private Context mContext;
    private Dialog dialog;
    private View contentView;


    public DialogPermissionTips(Context mContext) {
        this.mContext = mContext;
        initView(mContext);
    }

    /**
     * dialog初始化
     *
     * @param mContext
     */
    private void initView(Context mContext) {
        dialog = new Dialog(mContext, R.style.dialog_style);
        contentView= LayoutInflater.from(mContext).inflate(R.layout.item_permiss_tips, null);
        dialog.setContentView(contentView);
        Window win = dialog.getWindow();
        win.setGravity(Gravity.TOP);
        win.setWindowAnimations(R.style.DialogAnimationFade);
        win.setLayout(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
        dialog.setCanceledOnTouchOutside(true);
        dialog.setCancelable(true);

        tvTitle= (TextView) contentView.findViewById(R.id.tv_title);
        tvContent= (TextView) contentView.findViewById(R.id.tv_content);
        lineAll= (LinearLayout) contentView.findViewById(R.id.lineAll);
        lineAll.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });

    }



    public DialogPermissionTips setTitle(String title){
        tvTitle.setText(title);
        return this;
    }

    public DialogPermissionTips setContent(String title){
        tvContent.setText(title);
        return this;
    }



    /**
     * 对话框显示
     */
    public DialogPermissionTips show() {
        try {
            if (mContext == null) {
                return this;
            }

            if (dialog == null || dialog.isShowing()) {
                return this;
            }
            dialog.show();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return this;
    }

    public boolean isShow(){
        if(dialog==null){
            return false;
        }
        return dialog.isShowing();
    }


    /**
     * 对话框关闭
     */
    public DialogPermissionTips dismiss() {
        try {
            if (mContext == null) {
                return this;
            }

            dialog.dismiss();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return this;
    }

    @Override
    public void onClick(View v) {


    }



}

